package testActivitySelect;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-11-26
 * Time:16:22
 */
class myComparator implements Comparator<int[]> {
    @Override
    public int compare(int[] o1,int[] o2){
        return  o1[1] - o2[1];//o1-o2为升序 o2 - o1降序
    }
}
public class TestDemo {


    public static int getMaxCount(int[][] activitysTime){

        int count = 1;
        int finalTime = activitysTime[0][1];
        for (int i = 1; i < activitysTime.length; i++) {

            if (activitysTime[i][0] > finalTime){
                count++;
                finalTime = activitysTime[i][1];
            }
        }
        return  count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入活动的次数");
        int num = scanner.nextInt();
        int[][] activitysTime = new int[num][2];
        System.out.println("请输入每个活动的开始时间与结束时间");
        for (int i = 0; i < num; i++) {
            activitysTime[i][0] = scanner.nextInt();
            activitysTime[i][1] = scanner.nextInt();
        }
        Arrays.sort(activitysTime,new myComparator());
        int ret = getMaxCount(activitysTime);
        System.out.println("能参加的最多的活动是:" + ret);
    }
}
